/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mwt.xml.xdbforms.xformlayer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;

/**
 * Progetto Master Web Technology
 * @author Gianfranco Murador, Cristian Castiglia, Matteo Ferri
 */
public class XFormNameSpaceResolver implements NamespaceContext {

    Map<String, String> map = new HashMap<String, String>();

    /**
     *
     * @param prefix
     * @param uri
     */
    public void addBinding(String prefix, String uri) {

        map.put(prefix, uri);

    }

     /**
     *
     * @param map
     */
    public void addBindings(Map<String, String> map) {

        this.map.putAll(map);

    }


    /**
     *
     * @return
     */
    public boolean hasBinding() {
        return (map.size() > 0);
    }

    /**
     *
     * Do in ingresso il nome del prefisso e
     * mi restituisce l'uri del name space
     **/
    public String getNamespaceURI(String prefix) {

        if (prefix.equals("")) {
            return "";
        } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
            return XMLConstants.XML_NS_URI;
        } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
        } else {
            if (map.containsKey(prefix)) {
                return map.get(prefix);
            } else {
                return XMLConstants.NULL_NS_URI;
            }
        }


    }

    public String getPrefix(String namespaceURI) {
        return null;
    }

    public Iterator getPrefixes(String namespaceURI) {
        return null;
    }
}
